package com.gdufe.firesafe.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gdufe.firesafe.model.entity.HouseEntity;
import com.gdufe.firesafe.model.vo.ResponsibleForVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 房屋表
 *
 * @author Liu
 * @email
 * @date 2024-03-26 16:29:57
 */
@Mapper
public interface HouseDao extends BaseMapper<HouseEntity> {
    @Select("SELECT h.id, h.address, o.name as ownerName, h.fire_extinguisher_status, " +
            "h.smoke_detector_status, h.passage_unblock_status, h.gas_status, h.electricity " +
            "FROM `house` h LEFT JOIN `owner` o ON h.owner_id = o.id " +
            "WHERE (h.id = #{key} " +
            "OR h.address LIKE CONCAT('%', #{key}, '%') " +
            "OR o.name LIKE CONCAT('%', #{key}, '%')) " +
            "AND h.building_id = #{buildingId}")
    IPage<ResponsibleForVO> selectResponsibleForVOPage(IPage<ResponsibleForVO> page, @Param("key") String key, @Param("buildingId") Integer buildingId);
}
